import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTreeView, QVBoxLayout, QWidget, QMessageBox
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QStandardItem, QStandardItemModel


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("分列显示的文本框")
        self.resize(600, 400)

        # 创建QTreeView和QStandardItemModel
        self.tree_view = QTreeView(self)
        self.model = QStandardItemModel()

        # 添加列
        self.model.setColumnCount(3)
        self.model.setHeaderData(0, Qt.Horizontal, "列1")
        self.model.setHeaderData(1, Qt.Horizontal, "列2")
        self.model.setHeaderData(2, Qt.Horizontal, "列3")

        # 添加数据
        self.add_data()

        # 设置QTreeView的模型
        self.tree_view.setModel(self.model)

        # 布局
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        layout = QVBoxLayout()
        layout.addWidget(self.tree_view)
        central_widget.setLayout(layout)

    def add_data(self):
        # 添加数据到模型
        for row in range(5):
            for column in range(3):
                item = QStandardItem(f"数据{row + 1}_{column + 1}")
                self.model.setItem(row, column, item)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())